﻿using LY.DataAccess.Repository;
using LY.Entity;
using LY.Entity.Entities;
using LY.Entity.PageSearch;
using LY.Entity.SearchEntity;
using LY.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LY.Business.ServiceImpl
{
    public class InvestService : IInvestService
    {
        InvestRepository _repo;
        public InvestService()
        {
            _repo = new InvestRepository();
        }
        public PagedList<T_Investment_EX> QueryInvestList(InvestSearch search, PageView view)
        {
            return _repo.QueryInvestList(search, view);
        }
        public List<T_Investment_EX> QueryInvestList(int pageindex, int memberId)
        {
            return _repo.QueryInvestList(pageindex, memberId);
        }
        public int QueryInvestCount(int memberId)
        {
            return _repo.QueryInvestCount(memberId);
        }
        public T_Investment_EX GetInvest(int? Id)
        {
            return _repo.GetInvest(Id);
        }
        /// <summary>
        /// 显示最新投标的用户信息
        /// </summary>
        /// <returns></returns>
        public List<T_Investment_EX> GetInvestment()
        {
            return _repo.GetInvestment();
        }
        /// <summary>
        /// 显示投标的用户信息
        /// </summary>
        /// <returns></returns>
        public PagedList<T_Investment_EX> GetInvestmentList(int id, int projectid, ProjectSearch search, PageView view)
        {
            return _repo.GetInvestmentList(id, projectid, search, view);
        }



        public int SaveRept(int? projectid, string name, int? id, double fee)
        {
            return _repo.SaveRept(projectid, name, id, fee);
        }

        public int SaveReptPrincipal(int? projectid, string name, int? id, double? OutPay)
        {
            return _repo.SaveReptPrincipal(projectid, name, id, OutPay);
        }

        /// <summary>
        /// 用户投标排行
        /// </summary>
        /// <returns></returns>
        public List<T_Investment_EX> GetInverstmentRanking()
        {
            return _repo.GetInverstmentRanking();
        }

        //用户投资还款计划
        public List<T_RepaymentPlan_EX> GetRepList(int? tid, int mid)
        {
            return _repo.GetRepList(tid, mid);
        }

        //显示最新投标Id
        public int GetLastId()
        {
            return _repo.GetLastId();
        }

        //根据时间获取Id
        public int GetIdByCreatTime(DateTime time)
        {
            return _repo.GetIdByCreatTime(time);
        }

        //更新投资记录表的状态
        public int Update(string submitBidNo, DateTime time, int status)
        {
            return _repo.Update(submitBidNo, time, status);
        }

        //public int UpdateProject(string projectId, DateTime time, int status)
        //{
        //    return _repo.UpdateProject(projectId, time, status);
        //}

        //public int GetIdBySubmitNo(string submitNo)
        //{
        //    return _repo.GetIdBySubmitNo(submitNo);
        //}

        //项目已投金额
        public decimal MoneyCount(int projectId)
        {
            return _repo.MoneyCount(projectId);
        }

        //根据时间查询出投标的订单号
        public string GetBidNoByCreatTime(DateTime time)
        {
            return _repo.GetBidNoByCreatTime(time);
        }

        //根据标号查询出投资人的信息列表
        public List<T_Investment_EX> GetSftInvestment(int projectId)
        {
            return _repo.GetSftInvestment(projectId);
        }

        //根据submitbidno查询出一个对象
        public T_Investment_EX GetInvestmentBySubmitBidNo(string submitBidNo)
        {
            return _repo.GetInvestmentBySubmitBidNo(submitBidNo);
        }

        public int SaveInvestment(T_Investment investment)
        {
            if (investment.Id <= 0)
            {
                return (int)_repo.Insert(investment);
            }
            else
            {
                return (int)_repo.Update(investment);
            }
        }


        public T_Investment GetModelBySubmitBidNo(string submitBidNo)
        {
            return _repo.GetModelBySubmitBidNo(submitBidNo);
        }

        public List<T_Investment_EX> QueryInvestmentList(int projectid,int repaymentPlanId)
        {
            return _repo.QueryInvestmentList(projectid, repaymentPlanId);
        }


        public PagedList<T_Investment> QueryInvestmentList(InvestSearch search, PageView view)
        {
            return _repo.QueryInvestmentList(search, view);
        }

        public T_Investment GetModel(int id)
        {
            return _repo.GetModel(id);
        }
    }
}
